package com.supermarket.order.api.factory;

import com.supermarket.common.core.domain.R;
import com.supermarket.order.api.RemoteOrderService;
import com.supermarket.order.api.domain.OrderById;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class RemoteOrderFallbackFactory implements FallbackFactory<RemoteOrderService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteOrderFallbackFactory.class);
    @Override
    public RemoteOrderService create(Throwable cause) {
        log.error("订单服务调用失败:{}", cause.getMessage());
        return new RemoteOrderService() {
            @Override
            public R<List<OrderById>> getOrderListById(Long id) {
                return R.fail("获取订单列表失败:" + cause.getMessage());
            }

            @Override
            public R<Map<Long, List<OrderById>>> getOrderMapByUserIds(List<Long> userIds) {
                return R.fail("获取订单列表失败:" + cause.getMessage());
            }
        };
    }
}
